// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import iView from 'iview'
import 'iview/dist/styles/iview.css';
import api from '@/api/api'
import * as filters from '@/api/filters'
import VueLazyload from 'vue-lazyload'


Vue.use(iView);
Vue.use(api);
Vue.use(VueLazyload)

Object.keys(filters).forEach(v => Vue.filter(v, filters[v]))

Vue.config.productionTip = false
Vue.config.devtools = true

// 导航钩子
router.beforeEach((to, from, next) => {
  // debugger
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (sessionStorage.token) {
      next()
    } else {
      next({
        path:'/login',
        query:{
          redirect: to.fullPath
        }
      })
    }
  } else {
    next()
  }
  // iView.LoadingBar.start();
});

router.afterEach(route => {
  // iView.LoadingBar.finish();
});
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
